const users=require("../database/users")
const uuid=require("uuid")
const md5=require("md5")

module.exports=async (req,res)=>{
  const {tel,email,password}=req.body
  const userData=await users.find({tel})
  
  try{
    if(userData.length<1){
      await users.insertMany({
         userId:uuid.v1(),
         tel,email,
         nickName:"",
         password:md5(password),
         power:0,
         sex:"",
         avatar:"",
         pay:""
       })
       res.send({
         code:1,
         msg:"注册成功",
         data:null
       })
     }else{
       res.send({
         code:3,
         msg:"手机号已存在",
         data:null
       })
     }
  }catch(err){
    res.send({
      code:2,
      msg:"数据库操作错误",
      data:err.toString()
    })
  }
  
}